<template>
  <div>
    <el-table :data="all" border style="width: 100%">
      <el-table-column prop="id" label="规格编号" width="180"> </el-table-column>
      <el-table-column prop="specsname" label="规格名称" width="180"> </el-table-column>
      <el-table-column  label="规格属性">
        <template slot-scope="scoped">
          <div>
            <el-tag v-for="(item,index) in scoped.row.attrs" :key="index">{{item}}</el-tag>
          </div>
        </template>
      </el-table-column>
       <el-table-column  label="状态">
         <template slot-scope="scoped">
           <div>
             <el-button type="success" v-if="scoped.row.status==1">启用</el-button>
             <el-button type="info" v-if="scoped.row.status==2">禁用</el-button>
           </div>
         </template>
       </el-table-column>
        <el-table-column  label="操作">
           <template slot-scope="scoped">
           <div>
             <el-button type="success" @click="update(scoped.row.id)">编辑</el-button>
            <v-del type="success" @del="del(scoped.row.id)"></v-del>
           </div>
         </template>
        </el-table-column>
    </el-table>
    <el-pagination
  background
  layout="prev, pager, next"
  :total="totals" :page-size="mangeSize" @current-change="changePage" >
</el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import{specsdelete}from"../../../request/api.js"
import { successAlert, warningAlert } from "../../../utils/alert.js";
export default {
  props: [],
  components: {},
  data() {
    return {
    };
  },
  computed: {
    ...mapGetters({
      all:"specs/list",
      totals:"specs/total",
      mangeSize:"specs/size"
    }),
  },
  methods: {
    ...mapActions({
      list:"specs/asyncChangeList",
      totallist:"specs/asyncChangeTotal",
       totalpage:"specs/asyncChangePage"
    }),
    //删除
    del(id){
specsdelete({ id: id }).then(res=>{
  if(res.data.code==200){
    successAlert(res.data.msg)
    this.list()
    this.totallist()
  }else{
    warningAlert(res.data.msg)
  }
})
    },
    // 点击编辑
    update(id){
      this.$emit('update',id);
    },
    //当前页码数发生变化
    changePage(e){
      this.totalpage(e)
    }
  },
  mounted() {
    this.totallist()
    this.totalpage(1)
  },
};
</script>
<style scoped>
</style>